<extend name="layout/edit" />

<block name="HEADER">
	<style type="text/css">
		.layui-form-item-img-upload, .xw-form .layui-form-item-img{
			width: 140px;
			height: auto;
		}
		.xw-form .xw-form-table .sections>.table-cell{
			min-height: auto;
		}
		.xw-form .xw-form-formType-div{
			padding: 10px;
		}
	</style>
</block>

<block name="CONTENT">
    <control:form id="form"/>
    <script id="tpl-moneyGridTotal" type="text/html">
    	<div style="text-align: center;">
    		<span style="margin-right: 50px;">小计</span>
    		<span  style="margin-right: 50px;">账号总额：{{get}}</span>
    		<span  style="margin-right: 50px;">余额消费：{{consume}}</span>
    		<span  style="margin-right: 50px;">账号余额：{{money}}</span>
    	</div>
    </script>
    <script id="tpl-integralGridTotal" type="text/html">
    	<div style="text-align: center;">
    		<span style="margin-right: 50px;">小计</span>
    		<span  style="margin-right: 50px;">积分获赠：{{get}}</span>
    		<span  style="margin-right: 50px;">积分消费：{{consume}}</span>
    		<span  style="margin-right: 50px;">积分余额：{{money}}</span>
    	</div>
    </script>
	<script id="tpl-giftGridTotal" type="text/html">
		<div style="text-align: center;">
			<span style="margin-right: 50px;">小计</span>
			<span  style="margin-right: 50px;">收入：{{get}}</span>
			<span  style="margin-right: 50px;">支出：{{consume}}</span>
			<span  style="margin-right: 50px;">赠送余额：{{money}}</span>
		</div>
	</script>

	<script id="tpl-brokerageGridTotal" type="text/html">
		<div style="text-align: center;">
			<span style="margin-right: 50px;">小计</span>
			<span  style="margin-right: 50px;">收入：{{get}}</span>
			<span  style="margin-right: 50px;">支出：{{consume}}</span>
			<span  style="margin-right: 50px;">佣金余额：{{money}}</span>
		</div>
	</script>

</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
		ns.init = function(){

			var filter=[{"field":"id","opera":"=","value":__oid}];

			//累计消费
            consumeGrid = layui.grid.render("consumeGrid");
            consumeGrid.load(filter);
            consumeGrid.loadSuccess(function(e){
                var sum =0;
                for(var i=0;i<e.data.length;i++){
                    sum=sum+parseFloat(e.data[i]['number']);
                }
                form.setValue("consume_total",sum);
                $("#consume .line h3").append('<span style="margin-left: 30px;">'+sum+'</span>');

            });

            //线下消费
            offlineGrid = layui.grid.render("offlineGrid");
            offlineGrid.load(filter);

          	//账号余额
            var filter_bal=[{"field":"id","opera":"=","value":__oid}];
            var money = form.getValue("balance")?form.getValue("balance"):0;
            var balance_total = form.getValue("balance_total")?form.getValue("balance_total"):0;

            $("#money .line h3").append('<span style="margin-left: 30px;">'+money+'</span>');
            moneyGrid = layui.grid.render("moneyGrid");
            moneyGrid.load(filter_bal);
            moneyGrid.loadSuccess(function(e){
                $("#moneyGridTotal").html( template("tpl-moneyGridTotal",{
                    get:parseFloat(balance_total)+parseFloat(money),
                    consume:balance_total,
                    money:money
                }));
            });

          	//赠送余额
            var filter_bal=[{"field":"id","opera":"=","value":__oid}];
            var balance_gift = form.getValue("balance_gift")?form.getValue("balance_gift"):0;
            var balance_gift_get = form.getValue("balance_gift_get")?form.getValue("balance_gift_get"):0;
            var gift_zhichu = form.getValue("gift_zhichu")?form.getValue("gift_zhichu"):0;

            $("#gift .line h3").append('<span style="margin-left: 30px;">'+(parseFloat(balance_gift))+'</span>');
            giftGrid = layui.grid.render("giftGrid");
            giftGrid.load(filter_bal);
            giftGrid.loadSuccess(function(e){
                $("#giftGridTotal").html( template("tpl-giftGridTotal",{
                    get:balance_gift_get,
                    consume:gift_zhichu,
                    money:parseFloat(balance_gift)
                }));
            });


			//佣金账户
            var filter_bal=[{"field":"id","opera":"=","value":__oid}];
            var brokerage_total = form.getValue("brokerage_total") || 0;
            var brokerage_zhichu = form.getValue("brokerage_zhichu") || 0;

            $("#brokerage .line h3").append('<span style="margin-left: 30px;">'+(parseFloat(brokerage_total)-parseFloat(brokerage_zhichu)).toFixed(2)+'</span>');
            brokerageGrid = layui.grid.render("brokerageGrid");
            brokerageGrid.load(filter_bal);
            brokerageGrid.loadSuccess(function(e){
                $("#brokerageGridTotal").html( template("tpl-brokerageGridTotal",{
                    get:brokerage_total,
                    consume:brokerage_zhichu,
                    money:(parseFloat(brokerage_total)-parseFloat(brokerage_zhichu)).toFixed(2)
                }));
            });

          	
          	//积分余额
          	var integral = form.getValue("integral")?form.getValue("integral"):0;
            var integral_get = form.getValue("integral_get")?form.getValue("integral_get"):0;
            var integral_zhichu = form.getValue("integral_zhichu")?form.getValue("integral_zhichu"):0;

			$("#integral .line h3").append('<span style="margin-left: 30px;">'+integral+'</span>');
            integralGrid = layui.grid.render("integralGrid"); 
          	integralGrid.load(filter);
          	integralGrid.loadSuccess(function(e){
          		$("#integralGridTotal").html( template("tpl-integralGridTotal",{
          			get:integral_get,
          			consume:integral_zhichu,
          			money:integral
          		}));
          	});
          	
          	//推荐会员数量
          	var spread = form.getValue("spread_total")?form.getValue("spread_total"):0;
			$("#spread .line h3").append('<span style="margin-left: 30px;">'+spread+'</span>');
            spreadGrid = layui.grid.render("spreadGrid"); 
          	spreadGrid.load(filter);


		}


    	
        //保存
        ns.save=function(){
    		form.save(1).then(function(res){
            	form.opener.grid.load();
            });
        }
        
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



